﻿@using hc.epm.DataModel.Basic;
@using System.Collections.Generic;
@model IEnumerable<Base_Company>
@{
    ViewBag.Title = "第三方单位";
}
<div class="content-right date-wrap fl c" style="min-height:100px;margin-left:10px">
    <div class="search mt5">
        <form class="layui-form" action="" method="get">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" style="width:100px">名称 : </label>
                    <div class="layui-input-inline"><input type="text" name="name" id="name" placeholder="请输入名称" autocomplete="off" class="layui-input" value="@ViewBag.Name" /></div>
                </div>
                <input type="hidden" name="IsMultiple" id="IsMultiple" value=@ViewBag.IsMultiple />
                <input type="submit" class="layui-btn layui-btn-radius layui-btn-warm" lay-filter="search" value="搜 索" />
                <input type="button" class="layui-btn layui-btn-radius layui-btn-warm" lay-filter="search" value="选 择" id="selectContent" />
            </div>
        </form>
    </div>

</div>
<div class="main mt5" style="margin:0 10px">
    <div class="layui-form">
        <table class="layui-table">
            <thead>
                <tr>
                    <th width="6%" style="text-align:center">
                        <input type="checkbox" lay-skin="primary" lay-filter="allChoose" />
                    </th>
                    <th width="60" class="table-center">序号</th>
                    <th width="18%" class="table-center">单位编码</th>
                    <th class="table-center">单位名称</th>
                    @*<th class="table-center">单位类型</th>
                    <th class="table-center">单位地址</th>*@
                    <th class="table-center">操作</th>
                </tr>
            </thead>
            <tbody id="selectData">
                @{
                    int index = 0;
                }
                @if (Model != null && Model.LongCount() > 0)
                {
                    foreach (var item in Model)
                    {
                        index++;
                        <tr>
                            <td style="text-align:center">
                                <input type="checkbox" lay-skin="primary" />
                                <input type="hidden" name="ids" id="id-@item.SId" value="@item.SId" />
                            </td>
                            <td class="table-center">@index </td>
                            <td class="table-center">@item.Code</td>
                            <td class="table-center">@item.Name</td>
                            @*<td class="table-center">@item.Type</td>
                            <td class="table-center">@item.AddressInfo</td>*@
                            <td class="table-center"><a href="javascript:;" class="editor-link handle-blue" data-itemid="@item.SId" title="编辑" id="sel">选择</a></td>
                        </tr>
                    }
                }
                else
                {
                    <tr>
                        <td colspan="5" class="table-center">
                            暂无数据
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>

    <div id="page">
        <div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">
            <a href="javascript:;" class="layui-laypage-prev layui-disabled" data-page="0">上一页</a>
            <span class="layui-laypage-curr"><em class="layui-laypage-em"></em><em>1</em></span>
            <a href="javascript:;" class="layui-laypage-next layui-disabled" data-page="2">下一页</a>
            <span class="layui-laypage-skip">
                到第<input type="text" min="1" value="1" class="layui-input">页
                <button type="button" class="layui-laypage-btn">确定</button>
            </span>
            <span class="layui-laypage-count">共 6 条</span>
        </div>
    </div>
</div>
</div>
<script>
    //若无数据隐藏分页组件
    if ('@ViewBag.Total' == 0) {
        $("#page").hide();
    }
    $(function () {
        var bool=@ViewBag.IsMultiple;
        if (bool) {
            $('table tr').find('th:eq(6)').hide();
            $('table tr').find('td:eq(6)').hide();
        }
        else {
            $('table tr').find('th:eq(0)').hide();
            $('table tr').find('td:eq(0)').hide();
            $('#selectContent').hide();
        }
    });
    layui.use(['layer', 'form', 'element', 'laypage'], function () {
        var layer = layui.layer, form = layui.form, element = layui.element, $ = layui.jquery, laypage = layui.laypage;
        //分页
        laypage.render({
            elem: 'page',
            count: '@ViewBag.Total',
            curr: '@ViewBag.pageIndex',
            layout: ['prev', 'page', 'next', 'skip', 'count', ],
            jump: function (obj, first) {
                if (!first) {
                    //得到了当前页，用于向服务端请求对应数据
                    var curr = obj.curr;
                    var search = $("form").serialize();
                    window.location.href = "/Template/SelectCompany?pageIndex=" + curr + "&" + search;
                }
            }
        });
        form.on('checkbox(allChoose)', function (data) {
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function (index, item) {
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
    });


    //选择单位
    $("#selectData").on('click', '#sel', function () {
        var ids = $(this).parent("td").parent("tr").find("[type=hidden]").val();
        var names = $(this).parent("td").parent("tr").find("td").eq(3).text();
        parent.setComanyValue(names, ids);
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index);//关闭窗口
    });
    //选择单位
    $("#selectContent").click(function () {
        var ids = "", names = "";
        $(".layui-table tbody input").each(function () {
            if (this.checked === true) {
                if (ids == "") {
                    ids = $(this).parent("td").parent("tr").find("[type=hidden]").val();
                    names = $(this).parent("td").parent("tr").find("td").eq(3).text();
                } else {
                    ids = ids + ',' + $(this).parent("td").parent("tr").find("[type=hidden]").val();
                    names = names + ',' + $(this).parent("td").parent("tr").find("td").eq(3).text();
                }
            }
        });
        parent.setComanyValue(names, ids);
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index);//关闭窗口
    });
</script>